<?php
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Worker\Controller;
use Think\Model;
use Worker\Logic\WorkerLogic;
use Worker;

/**
 * 订单控制器
 * @author derek <693472824@qq.com>
 */
class OrdersController extends BaseController {
    
    /**
     * 订单列表
     */
    public function orderList(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        //1：可抢订单；2：待服务；4：待支付；6：已完成；7：退单
        $type = I('POST.type');
        if(!in_array($type, array('1', '2', '4', '6', '7'))){
            $this->rsp['rspCode'] = '422';
            $this->rsp['rspDesc'] = '参数异常';
            exit(json_encode($this->rsp));
        }
        
        //分页信息
        $page = I('POST.page');
        $page = is_numeric($page) && $page > 0 ? $page : 1;
        $start = ($page - 1) * $this->limit;
        
        $workerID = WorkerLogic::getIDByAccount($account);
        
        if($type == '1'){
            $map['status'] = '1';
            $orderBy = 'emergency DESC,appointment';
            
            //只允许抢本站点的订单
            $workerModel = M('Worker')->where(array('worker_id'=>$workerID))->find();
            $map['site_id'] = $workerModel['site_id'];
            
            //闲散小哥不允许抢紧急订单
            $memberType = I('POST.member_type') ? : $workerModel['member_type'];
            
            //如果站点无自有小哥，则允许闲散小哥抢紧急订单
            $workerSite = M('Worker')->where(array('site_id'=>$workerModel['site_id'], 'member_type'=>'1'))->find();
            
            if($memberType == '2' && !empty($workerSite)){
                $map['emergency'] = '1';
            }
            
        }elseif(in_array($type, array('2', '6', '7'))){
            $map['status'] = $type == '2' ? array('in', '2,3') : ($type == '6' ? array('in', '6,9') : $type);
            $map['worker_id'] = $workerID;
            
            if($type == '2'){
                $orderBy = 'status DESC,emergency DESC,appointment';
            }else{
                $orderBy = 'create_time DESC';
            }
        }elseif ($type == '4'){
            $map['status'] = array('in', '4,5,10');
            $map['worker_id'] = $workerID;
            $orderBy = 'status DESC,appointment DESC';
        }
        
        $view = D('Api/OrdersView');
        
        $count = $view->where($map)->count();
        $totalPage = intval(floor(($count + $this->limit - 1)/$this->limit));
        
        //若查询当前页数大于总页数，则表示当前查询的是最后一页
        $lastPage = $page >= $totalPage ? true : false;
        
        if($page <= $totalPage){
            
            $list = $view->where($map)->limit($start, $this->limit)
                        ->field('order_id,order_no,emergency,delay,appointment,order_type,end_time,status,detail_name,price')
                        ->order($orderBy)->select();          
        }
        
        $rspCont['lastPage'] = $lastPage;
        $rspCont['count'] = $count;
        $rspCont['orderList'] = is_array($list) ? $list : array();
        
        $this->rsp['rspCode'] = '200';
        $this->rsp['rspCont'] = $rspCont;
        
        exit(json_encode($this->rsp));
    }
    
    /**
     * 订单详情
     */
    public function viewDetail(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        //1：可抢订单；2：待服务
        $orderID = I('POST.order_id');
        $view = D('Api/OrdersView');
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $order = $view->where(array('order_id'=>$orderID))
                ->field('order_id,order_no,emergency,delay,appointment,order_type,worker_id,end_time,service_time,status,total,rate_price,remark,reason,contact,telphone,address,name,detail_id,detail_name,price')
                ->find();
        
        if(empty($order)){
            $this->rsp['rspCode'] = '315';
            $this->rsp['rspDesc'] = '此订单已被其它小哥抢单';
        }elseif (in_array($order['status'], array('1','7')) || $order['worker_id'] == $workerID){
            
            $orderMap['order_id'] = $orderID; 
            
            //用户上传维修图
            $recordModel = M('OrdersRecord');
            $recordList = $recordModel->where($orderMap)->field('fullpath')->select();
            
            //小哥已“发起支付”，此时有收费明细
            if(in_array($order['status'], array('4', '5', '6', '9', '10'))){
                $priceModel = M('OrdersPrice');
                $priceList = $priceModel->where($orderMap)->field('price_type,name,model,quantity,unit_price,total_price,agreement')->select();
                
                $evaluation = D('Api/EvaluationView')->where($orderMap)->field('ev_id,score,content,create_time,username,fullpath')->find();
            }
            
            $rspCont['recordList'] = empty($recordList) ? array() : $recordList;
            $rspCont['priceList'] = empty($priceList) ? array() : $priceList;
            $rspCont['evaluation'] = empty($evaluation) ? array('ev_id'=>'', 'score'=>'', 'content'=>'', 'create_time'=>'', 'username'=>'', 'fullpath'=>'') : $evaluation;
            
            unset($order['worker_id']);
            $rspCont['order'] = $order;
            
            $this->rsp['rspCode'] = '200';
            $this->rsp['rspCont'] = $rspCont;
        }elseif ($order['status'] == '8'){
            $this->rsp['rspCode'] = '316';
            $this->rsp['rspDesc'] = '此订单已转给其他小哥';
        }else{
            $this->rsp['rspCode'] = '315';
            $this->rsp['rspDesc'] = '此订单已被其它小哥抢单';
        }
        
        exit(json_encode($this->rsp));
    }
    
    /**
     * 订单开始、结束
     */
    public function service(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        //1：开始；2：结束
        $type = I('POST.type');
        $orderID = I('POST.order_id');
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $map['order_id'] = $orderID;
        $map['worker_id'] = $workerID;
        
        $orderModel = M('Orders');
        $order = $orderModel->where($map)->find();
        
        if($type == 1 && $order['status'] == 2){
            $data['status'] = '3';
            $data['start_time'] = NOW_TIME;
            
            $result = $orderModel->where($map)->save($data);
            
            //接单数加1
            M('Worker')->where(array('worker_id'=>$workerID))->setInc('orders_sum', 1);
            
            if($result !== false){
                $this->rsp['rspCode'] = '200';
            }
        }elseif($type == 2 && $order['status'] == 3){
            
            $serviceTime = intval((NOW_TIME - $order['start_time'])/60);        //单位：分钟
            
            $detailView = D('Api/OrdersDetailView');
            $detail = $detailView->where($map)->find();
            
            //固定费用：超范围服务费+工时费
            $total = 0;
            
            //按小时计费
            if($detail['unit'] == '23'){
            
                $remainder = $serviceTime%60;
                $int = intval($serviceTime/60);
            
                if($int == 0){
                    $price = $detail['price'];
                }else{
            
                    if($remainder > 10 && $remainder <= 40){
                        $int = $int + 0.5;
                    }elseif ($remainder > 40){
                        $int = $int + 1;
                    }
            
                    $price = $detail['price'] * $int;
                }
            
                $hourData['order_id'] = $orderID;
                $hourData['price_type'] = '2';
                $hourData['name'] = $detail['detail_name'];
                $hourData['model'] = '计时费';
                $hourData['quantity'] = $int;
                $hourData['unit_price'] = $detail['price'];
                $hourData['total_price'] = $price;
                $priceData[] = $hourData;
            
                $rspCont['total_price'] = $price;               //total_price 大于 0时表示计时费，前端不需再计算服务费
                $total = $price;
            }else{
                $rspCont['total_price'] = '0';                  //total_price 等于 0 时，前端需要计算服务费=单价 * 数量
            }
            
            //计算超范围服务器
            $view = D('Blovex4/OrdersView');
            $address = $view->where(array('Worker.worker_id'=>$workerID, 'Orders.order_id'=>$orderID))
                        ->field('order_id,latitude,longitude')->find();
            
            $work = M('Worker')->where(array('worker_id'=>$workerID))->find();
            
            $orderLogic = D('Api/Orders', 'Logic');
            $site = $orderLogic->getSite($address, $work['site_id']);
            
            //$siteModel = M('Site');
            //$site = $siteModel->where(array('site_id'=>$work['site_id']))->field('site_id,ROUND(6378.137*2*ASIN(SQRT(POW(SIN(('.$address['latitude']
                    //.'*PI()/180-latitude*PI()/180)/2),2)+COS('.$address['latitude'].'*PI()/180)*COS(latitude*PI()/180)*POW(SIN(('.$address['longitude']
                    //.'*PI()/180-longitude*PI()/180)/2),2)))*1000) AS juli')->order('juli')->find();
            //$tmp = $siteModel->getLastSql();
            
            if(!empty($site)){
            
                //根据经纬度计算的距离单位为米，超范围服务费中距离为千米，所以需做转换
                $distance = round($site['juli']/1000, 3);
                $price = $orderLogic->getChargePrice($site);
                
                //$chargeMap['minimum'] = array('ELT', $site['juli']);
                //$chargeMap['_string'] = ' (maximum = 0 OR maximum > '.$site['juli'].') ';
                //$price = M('Charge')->where($chargeMap)->getField('price');
            }else{
                $price = '0';
                $distance = '0';
            }
            
            $chargeData['order_id'] = $orderID;
            $chargeData['price_type'] = '4';
            $chargeData['name'] = '超范围服务费';
            $chargeData['model'] = $site['juli'] ? : '0';
            $chargeData['quantity'] = '1';
            $chargeData['unit_price'] = $price;
            $chargeData['total_price'] = $price;
            $priceData[] = $chargeData;
            
            M('OrdersPrice')->addAll($priceData);
            
            //更新订单信息（服务结束时间、时长、状态）
            $data['end_time'] = NOW_TIME;
            $data['service_time'] = $serviceTime;       //小哥服务时间
            $data['status'] = '10';
            $data['total'] = $total + $price;
            
            $result = $orderModel->where($map)->save($data);
            
            //更新平均工时
            D('Worker', 'Logic')->updateHour($workerID);      
            
            if($result !== false){
                
                //每个订单服务类型只有一种，因此订单结束时返回服务类型及单价
                //若服务类型按时计费，则计算服务费并返回前端，否则由前端计算费用
                $rspCont['detail_id'] = $detail['detail_id'];
                $rspCont['detail_name'] = $detail['detail_name'];
                $rspCont['price'] = $detail['price'];
                $rspCont['service_time'] = $serviceTime;
                
                $this->rsp['rspCode'] = '200';
                $this->rsp['rspCont'] = $rspCont;
            }else{
                $this->rsp['rspCode'] = '301';
                $this->rsp['rspDesc'] = '操作数据库异常';
            }
        }else{
            $this->rsp['rspCode'] = '422';
            $this->rsp['rspDesc'] = '参数异常';
        }
        
        exit(json_encode($this->rsp));
    }
    
    /**
     * 退订
     */
    public function unsubscribe(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        $orderID = I('POST.order_id');
        $reason = I('POST.reason');
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $map['order_id'] = $orderID;
        $map['worker_id'] = $workerID;
        
        $orderModel = M('Orders');
        $order = $orderModel->where($map)->find();
        
        if($order['status'] == '2' && !empty($reason)){
            $data['status'] = '7';
            $data['reason'] = $reason;
            $data['end_time'] = NOW_TIME;
            $orderModel->where($map)->save($data);
            
            $msgData['worker_id'] = $workerID;
            $msgData['site_id'] = $order['site_id'];
            $msgData['msg_type'] = '2';
            $msgData['order_id'] = $orderID;
            $msgData['content'] = '撤单';
            $msgData['create_time'] = NOW_TIME;
            $msgData['sender'] = $workerID;
            $msgData['receipt'] = '1';
            $msgData['receipt_time'] = NOW_TIME;
            
            $msgModel = M('Message');
            $result = $msgModel->add($msgData);
            
            $extra['msg_type'] = '2';
            $extra['content'] = '';
            $extra['order_id'] = $orderID;
            $extra['order_no'] = $order['order_no'];
            $extra['emergency'] = $order['emergency'];
            $extra['appointment'] = $order['appointment'];
            $extra['delay'] = $order['delay'];
            
            api('Util/jPush', array($account, array(), $extra));
            
            $this->rsp['rspCode'] = '200';
        }else{
            
            $this->rsp['rspCode'] = '422';
            $this->rsp['rspDesc'] = '参数异常';
        }
        
        exit(json_encode($this->rsp));
    }
    
    /**
     * 转单
     */
    public function transfer(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        $orderID = I('POST.order_id');
        $target = I('POST.t_account');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        $workerID = WorkerLogic::getIDByAccount($account);
        $targetID = WorkerLogic::getIDByAccount($target);
        
        if(!checkMobile($target) || empty($targetID)){
            $this->rsp['rspCode'] = '422';
            $this->rsp['rspDesc'] = '参数异常';
            exit(json_encode($this->rsp));
        }
        
        $map['order_id'] = $orderID;
        $map['worker_id'] = $workerID;
        
        $orderModel = M('Orders');
        $order = $orderModel->where($map)->find();
        
        //未开始前可转单
        if($order['status'] == '2'){
            
            $work = M('Worker')->where(array('worker_id'=>$workerID))->find();
            
            $data['worker_id'] = $targetID;
            $data['site_id'] = $work['site_id'];
            $data['order_type'] = '4';
            $data['sender'] = $order['sender'] ? : $workerID;
            $data['status'] = '8';
            
            $result = $orderModel->where($map)->save($data);
            
            //发送推送消息
            if($result !== false){
                
                $msgData['worker_id'] = $targetID;
                $msgData['site_id'] = $data['site_id'];
                $msgData['msg_type'] = '5';
                $msgData['order_id'] = $orderID;
                $msgData['content'] = '转单';
                $msgData['create_time'] = NOW_TIME;
                $msgData['sender'] = $workerID;
                $msgData['receipt'] = '2';
                $msgData['receipt_time'] = '0';
                
                $msgModel = M('Message');
                $result = $msgModel->add($msgData);
                
                $extra['msg_type'] = '5';
                $extra['content'] = '';
                $extra['order_id'] = $order['order_id'];
                $extra['order_no'] = $order['order_no'];
                $extra['emergency'] = $order['emergency'];
                $extra['appointment'] = $order['appointment'];
                $extra['delay'] = $order['delay'];
                
                api('Util/jPush', array($target, array(), $extra));
                
                $this->rsp['rspCode'] = '200';
            }else{
                $this->rsp['rspCode'] = '301';
                $this->rsp['rspDesc'] = '操作数据库异常';
            }
        }else{
            $this->rsp['rspCode'] = '302';
            $this->rsp['rspDesc'] = '未找到数据';
        }
        
        exit(json_encode($this->rsp));
    }
    
    /**
     * 小哥确认接单
     */
    public function confirm(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        $orderID = I('POST.order_id');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $map['order_id'] = $orderID;
        $map['worker_id'] = $workerID;
        $map['status'] = '8';
        
        $orderModel = M('Orders');
        $order = $orderModel->where($map)->find();
        
        if(!empty($order)){
            $data['status'] = '2';
            $result = $orderModel->where($map)->save($data);
            
            if($result !== false){
                
                $msgMap['worker_id'] = $workerID;
                $msgMap['order_id'] = $orderID;
                $msgMap['msg_type'] = array('in', array('5', '6', '7', '8'));
                
                $msgData['receipt'] = '1';
                $msgData['receipt_time'] = NOW_TIME;
                
                M('Message')->where($msgMap)->save($msgData);
                
                $this->rsp['rspCode'] = '200';
            }else{
            
                $this->rsp['rspCode'] = '301';
                $this->rsp['rspDesc'] = '操作数据库异常';
            }
        }else{
            $this->rsp['rspCode'] = '302';
            $this->rsp['rspDesc'] = '未找到数据';
        }
        
        exit(json_encode($this->rsp));
    }
    
    /**
     * 订单费用
     */
    public function price(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        $orderID = I('POST.order_id');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        $priceList = I('POST.priceList');
        if(is_string($priceList)){
            $priceList = stripslashes(html_entity_decode($priceList));
            $priceList = json_decode($priceList, true);
        }
        
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $orderModel = M('Orders');
        $order = $orderModel->where(array('order_id'=>$orderID, 'worker_id'=>$workerID))->find();
        
        if($order['status'] == '10'){
            
            $detailList = M('ClassDetail')->getField('detail_id,unit');
            
            $priceData = array();
            
            foreach ($priceList as $key=>$val){
                
                $price['order_id'] = $orderID;
                $price['price_type'] = $val['price_type'];
                $price['name'] = $val['name'];
                $price['model'] = $val['model'];
                $price['quantity'] = $val['quantity'];
                $price['unit_price'] = $val['unit_price'];
                $price['total_price'] = $val['total_price'];
                $price['agreement'] = $val['agreement'];
                
                if(in_array($price['price_type'], array('1', '2', '3'))){
                    
                    if($price['price_type'] == '2' && $detailList[$val['model']] == '23'){
                        continue;
                    }
                    
                    $priceData[] = $price;
                }
            }
            
            $priceModel = M('OrdersPrice');
            
            if(count($priceData) > 0){
                $priceModel->addAll($priceData);
            }
            
            $map['order_id'] = $orderID;
            $totalPrice = $priceModel->where($map)->sum('total_price');
            
            //修改订单总费用/订单状态为等支付
            $orderData['total'] = $totalPrice;
            $orderData['status'] = '4';
            $result = $orderModel->where($map)->save($orderData);
            
            if($result !== false){
                $this->rsp['rspCode'] = '200';
            }else{
                $this->rsp['rspCode'] = '301';
                $this->rsp['rspDesc'] = '操作数据库异常';
            }
        }else{
        
            $this->rsp['rspCode'] = '422';
            $this->rsp['rspDesc'] = '参数异常';
        }

        exit(json_encode($this->rsp));
    }
    
    /**
     * 抢单
     */
    public function scramble(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        $orderID = I('POST.order_id');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $map['order_id'] = $orderID;
        $map['status'] = '1';
        
        $data['order_type'] = '1';
        $data['worker_id'] = $workerID;
        $data['status'] = '2';
        
        $orderModel = M('Orders');
        $result = $orderModel->where($map)->save($data);
        
        if($result == 1){
            
            $map['status'] = '2';
            $order = $orderModel->where($map)->find();
            
            $msgData['worker_id'] = $workerID;
            $msgData['site_id'] = $order['site_id'];
            $msgData['msg_type'] = '3';
            $msgData['order_id'] = $orderID;
            $msgData['content'] = '抢单成功，订单号：'.$order['order_no'];
            $msgData['create_time'] = NOW_TIME;
            $msgData['sender'] = $workerID;
            $msgData['receipt'] = '1';
            $msgData['receipt_time'] = NOW_TIME;
            
            $msgModel = M('Message');
            $result = $msgModel->add($msgData);
            
            $extra['msg_type'] = '3';
            $extra['content'] = '';
            $extra['order_id'] = $orderID;
            $extra['order_no'] = $order['order_no'];
            $extra['emergency'] = $order['emergency'];
            $extra['appointment'] = $order['appointment'];
            $extra['delay'] = $order['delay'];
            
            api('Util/jPush', array($account, array(), $extra));
            
            $this->rsp['rspCode'] = '200';
        }else{
            
            $this->rsp['rspCode'] = '305';
            $this->rsp['rspDesc'] = '该订单已被其他小哥抢单';
        }
            
        exit(json_encode($this->rsp));
    }
    
    /**
     * 确认现金支付
     */
    public function cash(){
        
        $account = I('POST.account');
        $token = I('POST.token');
        $orderID = I('POST.order_id');
        
        if(!$this->checkToken($account, $token)){
        
            $this->rsp['rspCode'] = '405';
            $this->rsp['rspDesc'] = '权限判断失败';
            exit(json_encode($this->rsp));
        }
        
        $workerID = WorkerLogic::getIDByAccount($account);
        
        $map['order_id'] = $orderID;
        $map['worker_id'] = $workerID;
        $map['status'] = '5';
        
        $orderModel = M('Orders');
        $order = $orderModel->where($map)->find();
        
        if(!empty($order)){
            
            $data['status'] = '6';
            //$data['coupon_id'] = '0';
            //$data['rate_price'] = $order['total'];
            //$data['turnover'] = $order['total'];        //交易额 = 实际支付金额 + 优惠券金额 * 后台设置比例SUBSIDY_PROPORTION 
            //$data['pay_type'] = '2';
            
            $result = $orderModel->where($map)->save($data);
            
            if($result !== false){
                
                //修改小哥账户余额
                
                //完整的公式（李经理20160706提供）：
                // 每一笔订单的交易额=用户实际支付的金额（含在线支付和线下现金） + （优惠券抵扣掉的金额*后台设置的补贴比例）
                // 闲散小哥的余额：
                //    如果是线上交易，每一笔交易，小哥余额增加：交易额*给小哥的绩效比例
                //    如果是线下交易，每一笔交易，小哥余额减少：交易额*（1-给小哥的绩效比例）
                // 自有小哥的账户余额 = 该小哥完成的所有订单的交易额 * 后台设置的绩效比例
                
                $workerModel = M('Worker');
                $workerMap['worker_id'] = $workerID;
                $worker = $workerModel->where($workerMap)->find();
                
                //自有团队成员
                if($worker['member_type'] == '1'){
                    //$proportion = C('TEAM_PROPORTION') ? : '80';
                    //$balance = round($order['total'] * $proportion/100, 2);
                    //$workerModel->where($workerMap)->setInc('balance', $balance);
                    
                    //自有小哥账户余额减少 用户支付的现金金额，以便强制要求小哥上交现金
                    //小哥上交后，自有小哥账户余额增加金额 = 现金金额 + 该订单绩效金额
                    $workerModel->where($workerMap)->setDec('balance', $order['rate_price']);
                    $status = '2';
                }elseif ($worker['member_type'] == '2'){
                    $proportion = C('COMMISSION_PROPORTION') ? : '70';
                    $balance = round($order['turnover'] * (1-$proportion/100), 2);
                    $workerModel->where($workerMap)->setDec('balance', $balance);
                    $status = '1';
                }
                
                $cashData['worker_id'] = $worker['worker_id'];
                $cashData['op_type'] = '4';
                $cashData['order_id'] = $orderID;
                $cashData['previous'] = $worker['balance'];
                $cashData['cash'] = $worker['member_type'] == '1' ? $order['rate_price'] : $balance;
                $cashData['balance'] = $worker['balance'] - $cashData['cash'];
                $cashData['status'] = $status;                  //自有小哥 status = 2 表示需上交现金
                $cashData['create_time'] = NOW_TIME;
                $cashData['admin_id'] = '0';
                
                M('WorkerCash')->add($cashData);
                
                $this->rsp['rspCode'] = '200';
            }else{
                $this->rsp['rspCode'] = '301';
                $this->rsp['rspDesc'] = '操作数据库异常';
            }
        }else{
            
            $this->rsp['rspCode'] = '422';
            $this->rsp['rspDesc'] = '参数异常';
        }
            
        exit(json_encode($this->rsp));
    }
}
